package org.xtext.tcc.generator;

import com.google.inject.Inject;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.IQualifiedNameProvider;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.eclipse.xtext.xtend2.lib.StringConcatenation;
import org.xtext.tcc.TccdslExtensions;
import org.xtext.tcc.tccdsl.Entity;
import org.xtext.tcc.tccdsl.Function;
import org.xtext.tcc.tccdsl.Type;

@SuppressWarnings("all")
public class AspectExtensions extends TccdslExtensions {
  
  @Inject
  private IQualifiedNameProvider nameProvider;
  
  public StringConcatenation aspect(final Entity e) {
    StringConcatenation _builder = new StringConcatenation();
    {
      EObject _eContainer = e.eContainer();
      if ((_eContainer instanceof org.xtext.tcc.tccdsl.Package)) {
        _builder.append("package ");
        String _packageName = this.packageName(e);
        _builder.append(_packageName, "");
        _builder.append(".aspect;");
        _builder.newLineIfNotEmpty();} else {
        _builder.append("package aspect;");
        _builder.newLine();
      }
    }
    _builder.newLine();
    _builder.append("import java.util.List;");
    _builder.newLine();
    _builder.append("import ");
    QualifiedName _fullyQualifiedName = this.nameProvider.getFullyQualifiedName(e);
    _builder.append(_fullyQualifiedName, "");
    _builder.append(";");
    _builder.newLineIfNotEmpty();
    _builder.newLine();
    _builder.append("public aspect Aspecto");
    String _name = e.getName();
    String _firstUpper = StringExtensions.toFirstUpper(_name);
    _builder.append(_firstUpper, "");
    _builder.append("{");
    _builder.newLineIfNotEmpty();
    {
      EList<Function> _functions = e.getFunctions();
      for(Function f : _functions) {
        _builder.append("\t");
        _builder.append("pointcut metodo");
        String _name_1 = f.getName();
        String _firstUpper_1 = StringExtensions.toFirstUpper(_name_1);
        _builder.append(_firstUpper_1, "	");
        _builder.append("(): call (* ");
        String _packageName_1 = this.packageName(e);
        _builder.append(_packageName_1, "	");
        _builder.append(".control.");
        String _name_2 = e.getName();
        String _firstUpper_2 = StringExtensions.toFirstUpper(_name_2);
        _builder.append(_firstUpper_2, "	");
        _builder.append("Controller.");
        String _name_3 = f.getName();
        _builder.append(_name_3, "	");
        _builder.append("(..));");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("pointcut metodo");
        String _name_4 = f.getName();
        String _firstUpper_3 = StringExtensions.toFirstUpper(_name_4);
        _builder.append(_firstUpper_3, "	");
        _builder.append("2(): call (public static ");
        {
          Type _type = f.getType();
          boolean _operator_notEquals = ObjectExtensions.operator_notEquals(_type, null);
          if (_operator_notEquals) {
            Type _type_1 = f.getType();
            String _name_5 = _type_1.getName();
            _builder.append(_name_5, "	");} else {
            _builder.append("void");
          }
        }
        _builder.append(" ");
        String _packageName_2 = this.packageName(e);
        _builder.append(_packageName_2, "	");
        _builder.append(".control.");
        String _name_6 = e.getName();
        String _firstUpper_4 = StringExtensions.toFirstUpper(_name_6);
        _builder.append(_firstUpper_4, "	");
        _builder.append("Controller.");
        String _name_7 = f.getName();
        _builder.append(_name_7, "	");
        _builder.append("(");
        String _aspectParameters = this.aspectParameters(f);
        _builder.append(_aspectParameters, "	");
        _builder.append("));");
        _builder.newLineIfNotEmpty();
      }
    }
    _builder.append("\t");
    _builder.newLine();
    {
      EList<Function> _functions_1 = e.getFunctions();
      for(Function f_1 : _functions_1) {
        _builder.append("\t");
        _builder.append("before(): metodo");
        String _name_8 = f_1.getName();
        String _firstUpper_5 = StringExtensions.toFirstUpper(_name_8);
        _builder.append(_firstUpper_5, "	");
        _builder.append("(){");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("System.out.println(thisJoinPoint.getSignature() + \" - Conectou!\");");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("after() returning: metodo");
        String _name_9 = f_1.getName();
        String _firstUpper_6 = StringExtensions.toFirstUpper(_name_9);
        _builder.append(_firstUpper_6, "	");
        _builder.append("2(){");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append("\t");
        _builder.append("System.out.println(thisJoinPoint.getSignature() + \" - Inseriu!\");");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
      }
    }
    _builder.append("}");
    _builder.newLine();
    return _builder;
  }
}